﻿using WebApplication1.Models;
using WebApplication1.RepositoryRealize.IRepository;
using WebApplication1.Service.IService;

namespace WebApplication1.Service
{
    public class UserService : IUserService
    {
        private readonly IUserRepository _userRepository;
        public UserService(IUserRepository userRepository) {

            _userRepository = userRepository;
        }

        public Task<long> AddUserAsync(userinfo userinfo)
        {
            string insertsql = "insert into userinfo(userid,username,sex,gangweiId,lingdaoid) VALUES(@userid,@username,@sex,@gangweiId,@lingdaoid);";
          return  _userRepository.Insert(userinfo,insertsql);
        }

  
        public async Task<object> GetUserAllAsync()
        {
            string sql = "select * from userinfo ;";
          return await  _userRepository.Select(sql);
        }

        public async Task<long> UpdateAsync(userinfo userinfo)
        {
            string sqlUpdate = "update  userinfo u set   username=@username where userid=@userid";

            return await _userRepository.Update(userinfo, sqlUpdate);
        }

        public async Task<long> RemoveAsync(int id) {
            string sqlDelect = "DELETE from userinfo where userid=@id";

       return     await _userRepository.Delete(id, sqlDelect);


        }

        public Task<long> DeleteAsync(long id)
        {
            throw new NotImplementedException();
        }
    }
}
